-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from RemarkableTools/dev
Dev
- Loading branch information
Showing
16 changed files
with
231 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Mx.NET.SDK.Core.Domain.Values; | ||
|
||
namespace Mx.NET.SDK.Core.Domain.Codec | ||
{ | ||
public class StringBinaryCodec : IBinaryCodec | ||
{ | ||
private readonly BytesBinaryCodec _bytesBinaryCodec; | ||
|
||
public StringBinaryCodec() | ||
{ | ||
_bytesBinaryCodec = new BytesBinaryCodec(); | ||
} | ||
public string Type => TypeValue.BinaryTypes.String; | ||
|
||
public (IBinaryType Value, int BytesLength) DecodeNested(byte[] data, TypeValue type) | ||
{ | ||
var (value, bytesLength) = _bytesBinaryCodec.DecodeNested(data, type); | ||
return (StringValue.FromUtf8(value.ValueOf<StringValue>().ToString()), bytesLength); | ||
} | ||
|
||
public IBinaryType DecodeTopLevel(byte[] data, TypeValue type) | ||
{ | ||
return new StringValue(data, type); | ||
} | ||
|
||
public byte[] EncodeNested(IBinaryType value) | ||
{ | ||
var stringValueObject = value.ValueOf<StringValue>(); | ||
var buffer = BytesValue.FromUtf8(stringValueObject.ToString()); | ||
|
||
return _bytesBinaryCodec.EncodeNested(buffer); | ||
} | ||
|
||
public byte[] EncodeTopLevel(IBinaryType value) | ||
{ | ||
var bytes = value.ValueOf<StringValue>(); | ||
return bytes.Buffer; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...NET.SDK.Core/Domain/Values/StructField.cs → src/Mx.NET.SDK.Core/Domain/Values/Field.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Text; | ||
using Mx.NET.SDK.Core.Domain.Helper; | ||
|
||
namespace Mx.NET.SDK.Core.Domain.Values | ||
{ | ||
public class StringValue : BaseBinaryValue | ||
{ | ||
public string Value { get; } | ||
public byte[] Buffer { get; } | ||
|
||
public StringValue(byte[] data, TypeValue type) : base(type) | ||
{ | ||
Buffer = data; | ||
Value = Encoding.UTF8.GetString(data); | ||
} | ||
|
||
public static StringValue FromUtf8(string utf8String) | ||
{ | ||
return new StringValue(Encoding.UTF8.GetBytes(utf8String), TypeValue.StringValue); | ||
} | ||
|
||
public static StringValue FromHex(string hexString) | ||
{ | ||
return new StringValue(Converter.FromHexString(hexString), TypeValue.StringValue); | ||
} | ||
|
||
public static StringValue FromBuffer(byte[] data) | ||
{ | ||
return new StringValue(data, TypeValue.StringValue); | ||
} | ||
|
||
public int GetLength() | ||
{ | ||
return Value.Length; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return Value; | ||
} | ||
|
||
public override string ToJson() | ||
{ | ||
return ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.