Bonjour
Je m'interroge sur la maniere la plus rationnelle de transfere un Stream dans une classe sachant que le stream contient l'image de la classe
Pour le moment je travaille en deux phases :
1- Je lit le stream depuis un Fichier a l'aide d'un StreamReader et je recupere un array de bytes
2- Je transfere l'array de byte au constructeur de ma classe qui instancie un BinaryReader et un MemoryStream pour transferer le contenu du Byte[] dans chaque element de ma
Je suis preneur de toutes propositions plus rationelle pour la conversion du Byte[] si c'est possible !
Merci de votre aide
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 public class C_GData { public UInt32 PSN; public byte[] HMS; public byte[] DMY; public Int32 SYNCAGE; public byte[] LAT; public byte[] LONG; public byte[] ALT; public byte NAVSTAT; public byte[] SOG; public byte[] COG; public byte GUS; public byte[] PDOP; public byte[] HDOP; public byte[] VDOP; public Int32 GPSDIST; public byte GSMSTAT; public byte[] MCC; public byte MCN; public byte[] GPRSIP; public byte[] SYSUPTIME; public byte[] DLOG; public byte[] ALARMS; public byte[] ADCVIN; public byte[] ADCVACC; public byte[] ADCTEMP; public byte IOSTAT; public byte[] CHANGEDSYSTEM; public byte[] SYSTEMFLAG; public byte SBN; public byte SWV; public bool isValid = true; public C_GData(byte[] BData) { Decode(BData); } private void Decode(byte[] BData) { using (MemoryStream bs = new MemoryStream(BData)) { BinaryReader br = new BinaryReader(bs, Encoding.Default); PSN = br.ReadUInt32(); HMS = br.ReadBytes(3); DMY = br.ReadBytes(4); SYNCAGE = br.ReadInt32(); LAT = br.ReadBytes(4); LONG = br.ReadBytes(5); ALT = br.ReadBytes(3); NAVSTAT = br.ReadByte(); SOG = br.ReadBytes(3); COG = br.ReadBytes(3); GUS = br.ReadByte(); PDOP = br.ReadBytes(2); HDOP = br.ReadBytes(2); VDOP = br.ReadBytes(2); GPSDIST = br.ReadInt32(); GSMSTAT = br.ReadByte(); MCC = br.ReadBytes(2); MCN = br.ReadByte(); GPRSIP = br.ReadBytes(4); SYSUPTIME = br.ReadBytes(5); DLOG = br.ReadBytes(2); ALARMS = br.ReadBytes(4); ADCVIN = br.ReadBytes(2); ADCVACC = br.ReadBytes(2); ADCTEMP = br.ReadBytes(2); IOSTAT = br.ReadByte(); CHANGEDSYSTEM = br.ReadBytes(4); SYSTEMFLAG = br.ReadBytes(8); SBN = br.ReadByte(); SWV = br.ReadByte(); } }
Partager