-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
44 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Google.Protobuf; | ||
using WPIUtil.Serialization.Protobuf; | ||
|
||
namespace WPIUtil.Logging; | ||
|
||
public sealed class ProtobufLogEntry<T, MessageType> : DataLogEntry where MessageType : IMessage | ||
where T : IProtobufSerializable<T, MessageType> | ||
{ | ||
private readonly ProtobufBuffer<T, MessageType> m_storage = new(); | ||
private readonly object m_lockObject = new(); | ||
|
||
private ProtobufLogEntry(DataLog log, string name, IProtobufBase proto, string metadata = "", long timestamp = 0) : base(log, name, proto.TypeString, metadata, timestamp) | ||
{ | ||
log.AddSchema(proto, timestamp); | ||
} | ||
|
||
public ProtobufLogEntry<T, MessageType> Create(DataLog log, string name, string metadata = "", long timestamp = 0) | ||
{ | ||
return new ProtobufLogEntry<T, MessageType>(log, name, T.Proto, metadata, timestamp); | ||
} | ||
|
||
public void Append(T value, long timestamp = 0) | ||
{ | ||
try | ||
{ | ||
lock (m_lockObject) | ||
{ | ||
m_log.AppendRaw(m_entry, m_storage.Write(value), timestamp); | ||
} | ||
} | ||
catch | ||
{ | ||
// ignore | ||
} | ||
} | ||
} |
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