forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloatSerializer.cs
More file actions
37 lines (31 loc) · 1.19 KB
/
Copy pathFloatSerializer.cs
File metadata and controls
37 lines (31 loc) · 1.19 KB
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
// -----------------------------------------------------------------------
// <copyright file="FloatSerializer.cs" company="Asynkron HB">
// Copyright (C) 2015-2017 Asynkron HB All rights reserved
// </copyright>
// -----------------------------------------------------------------------
using System;
using System.IO;
using Wire.Internal;
namespace Wire.ValueSerializers
{
public class FloatSerializer : SessionAwareByteArrayRequiringValueSerializer<float>
{
public const byte Manifest = 12;
public const int Size = sizeof(float);
public static readonly FloatSerializer Instance = new FloatSerializer();
public FloatSerializer() : base(Manifest, () => WriteValueImpl, () => ReadValueImpl)
{
}
public override int PreallocatedByteBufferSize => Size;
public static void WriteValueImpl(Stream stream, float f, byte[] bytes)
{
NoAllocBitConverter.GetBytes(f, bytes);
stream.Write(bytes, 0, Size);
}
public static float ReadValueImpl(Stream stream, byte[] bytes)
{
stream.Read(bytes, 0, Size);
return BitConverter.ToSingle(bytes, 0);
}
}
}